﻿@using FurnitureDesign.Mvc.Models.Products;
@model ProductViewModel

<form class="layui-form" id="frmAdd">
    <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" asp-for="Id" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" asp-for="ProductName"></label>
        <div class="layui-input-block">
            <input type="text" asp-for="ProductName" required placeholder="请输入产品名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" asp-for="ProductmMterial"></label>
        <div class="layui-input-block">
            <input type="text" asp-for="ProductmMterial" required placeholder="请输入产品材质" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" asp-for="Price"></label>
        <div class="layui-input-block">
            <input type="text" asp-for="Price" placeholder="请输入产品售价" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" asp-for="MarketValue"></label>
        <div class="layui-input-block">
            <input type="text" asp-for="MarketValue" required placeholder="请输入市场价" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" asp-for="Brand"></label>
        <div class="layui-input-block">
            <input type="text" asp-for="Brand" required placeholder="请输入品牌" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" asp-for="Colour"></label>
        <div class="layui-input-block">
            <input type="text" asp-for="Colour" required placeholder="请输入颜色" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" asp-for="ProductTypeName"></label>
        <div class="layui-input-block">
            <select asp-for="ProductTypeId" asp-items="@ViewBag.ProductList"></select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*">修改</button>
        </div>
    </div>
</form>
@section Scripts{
    <script>
        layui.use(['form', 'layer'], function () {
            var form = layui.form; //表单组件
            var $ = layui.$;
            var layer = layui.layer;//弹出层组件


            //监听提交事件sumbmit,*表示那个提交按钮，过滤器名
            form.on('submit(*)', function (data) {
                var str = $("#frmAdd").serialize();//表单序列化
                console.log(str);
                //$.post(地址,向服务器传的参数,回调函数,返回值类型)
                $.post("/Admin/Product/Edit", str, function (re) {
                    if (re.success) {
                        parent.layer.msg("修改成功");//parent父窗体
                        parent.layui.$("#btnSearch").click();//调用你窗体中的查询按钮的单击事件实现，数据刷新
                        //当你在iframe页面关闭自身时
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    } else {
                        layer.msg("修改失败");
                    }                    
                }, "json");
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
        });
    </script>
}